{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2024 Teclib' and contributors.
 # @copyright 2003-2014 by the INDEPNET Development Team.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{% import 'components/form/basic_inputs_macros.html.twig' as inputs %}
{% import 'components/form/fields_macros.html.twig' as fields %}

{% set rand = random() %}
{% set field_options = {
    'field_class': 'col-4',
} %}
<div>
    <form method="post" action="{{ 'Profile_User'|itemtype_form_path }}" data-submit-once>
        <div class="card-body d-flex flex-wrap p-0 mt-n3">
            <div class="col-12 flex-column">
                <div class="d-flex flex-row flex-wrap flex-xl-nowrap">
                    <div class="row flex-row align-items-start flex-grow-1">
                        <div class="row flex-row">
                            {{ inputs.hidden('_glpi_csrf_token', csrf_token()) }}
                            {{ inputs.hidden(source_itemtype|itemtype_foreign_key, source_items_id) }}
                            {{ fields.largeTitle(__('Add an authorization to a user')) }}
                            {% if source_itemtype != 'Entity' %}
                                {{ fields.dropdownField('Entity', 'entities_id', session('glpiactive_entity'), 'Entity'|itemtype_name, {
                                    'entity': session('glpiactiveentities')
                                }|merge(field_options)) }}
                            {% endif %}
                            {% if source_itemtype != 'Profile' %}
                                {{ fields.dropdownField('Profile', 'profiles_id', null, 'Profile'|itemtype_name, {
                                    'condition': {
                                        'WHERE': call('Profile::getUnderActiveProfileRestrictCriteria')
                                    },
                                    'display_emptychoice': false,
                                }|merge(field_options)) }}
                            {% endif %}
                            {% if source_itemtype != 'User' %}
                                {{ fields.dropdownField('User', 'users_id', null, 'User'|itemtype_name, {
                                    'display_emptychoice': false,
                                    'entity': session('glpiactiveentities'),
                                    'right': 'all',
                                    'used': used_users
                                }|merge(field_options)) }}
                            {% endif %}
                            {{ fields.dropdownYesNo('is_recursive', 0, __('Recursive'), field_options) }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="card-body mx-n2 border-top d-flex flex-row-reverse align-items-start flex-wrap py-2">
            {{ inputs.submit('add', _x('button', 'Add')) }}
        </div>
    </form>
</div>
